<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-default navbar-btn" href="${base}/platform/school" data-pjax ><i class="ti-angle-left" id="goback"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/school/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                   		<div class="form-group">
                            <label for="region_id" class="col-sm-2 control-label">所属片区</label>
							
                            <div class="col-sm-8">
                                <select id="region_id" name="region_id" class="form-control" >
                                	<%for(region in obj.regions){%>
                                		 <option value="${region.id}">${region.name}</option>
                                	<%}%>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">名称</label>

                            <div class="col-sm-8">
                                <input type="text" id="name" class="form-control" name="name" required="required"  placeholder="名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="code" class="col-sm-2 control-label">编号</label>

                            <div class="col-sm-8">
                                <input type="text" id="code" class="form-control" name="code" required="required" placeholder="编号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="is_branch" class="col-sm-2 control-label">是否分校</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="is_branch" required="required"  value="1"  />是
                                 <input type="radio" name="is_branch" required="required"  value="0"  />否
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="linkman" class="col-sm-2 control-label">联系人</label>
                            
                            <div class="col-sm-8">
                                <input type="text" id="linkman" class="form-control" name="linkman" required="required"   placeholder="联系人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="phone" class="col-sm-2 control-label">电话</label>

                            <div class="col-sm-8">
                                <input type="text" id="phone" class="form-control" name="phone"   required="required"  placeholder="电话">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">地址</label>

                            <div class="col-sm-8">
                                <input type="text" id="address" class="form-control" name="address"   required="required"  placeholder="地址">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">状态</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="state" required="required"  value="0"  />正常
                                 <input type="radio" name="state" required="required"  value="-1"  />未启用
                                 <input type="radio" name="state" required="required"  value="1"  />停用
                            </div>
                        </div>
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">区域范围</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input id="parentId" type="text" class="form-control" placeholder="选择区域" disabled value="<%if(!isEmpty(obj)){%>${obj.name}<%}%>" required="required" />

			                             		<span class="input-group-btn">
			                             			<button type="button" class="btn btn-primary" data-toggle="modal"
                                                            data-target="#dialogSelectParentUnit"><i class="ti-plus"></i>选择
                                                    </button>
			                             		</span>
                                </div>
                                <input type="hidden" name="areaid" value="<%if(!isEmpty(obj)){%>${obj.id}<%}%>">
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<!-- 选择上级单位 -->
<div id="dialogSelectParentUnit" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">选择区域</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="jsTreeParentUnit" class="demo"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" onclick="selectParentMenu()">确认选择</button>
            </div>
        </div>
    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
	function initTreeView() {
	    $("#jsTreeParentUnit").jstree({
	        plugins: ["wholerow","json_data","checkbox","ui",],
	        core: {
	            data: {
	                dataType: "json",
	                url: function (node) {
	                    return node.id === "#" ? "${base}/platform/school/tree" : "${base}/platform/school/tree?pid=" + node.id
	                }
	            },
	            multiple: true
	        }
	    }).on("dblclick.jstree", function (node) {
	        selectParentMenu();
	    });
	}
	//选择父菜单
    function selectParentMenu() {
        var tree = $.jstree.reference("#jsTreeParentUnit");
        var node = tree.get_selected(true);
        var namevar= "";
        var idvar= "";
        for(var i=0;i<node.length;i++){
        	namevar+=node[i].text+",";
        	idvar+=node[i].id+",";
        }
        namevar=namevar.substring(0,namevar.length-1);
        idvar=idvar.substring(0,idvar.length-1);
        $("#addForm #parentId").val(namevar);
        $("#addForm input[name='areaid']").val(idvar);
        $("#dialogSelectParentUnit").modal("hide");
    }
    $(document).ready(function () {
    	initTreeView();
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 500);
                } else {
                    Toast.error(data.msg);
                }
            }
        });
    });
</script>
<%}%>